package com.xianggu.demo;

import org.springframework.util.AntPathMatcher;

import java.util.Map;

/**
 * @author chengjy
 * @date 2025/3/23
 */
public class Demo01 {

    //Spring 提供的 AntPathMatcher 支持通配符匹配，适合处理动态路径模板。
    public static void main(String[] args) {
        String path = "/getById/1286142373594481742";
        String value = "/getById/{id}";
        String pattern  = "/getById/{id}";

        if( path.startsWith( value)){
            String pathParam = path.substring(value.length(), path.length());
            System.out.println(pathParam);
        }

        AntPathMatcher matcher = new AntPathMatcher();
        if (matcher.match(value, path)) {
            // 提取路径参数（返回 Map<String, String>）
            Map<String, String> params = matcher.extractUriTemplateVariables(value, path);
            String id = params.get("id");
            System.out.println(id); // 输出 1286142373594481742
        }
    }
}
